package subject_set.offer100;

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode(int x) {
        val = x;
    }
}

/**
 * @author haomin
 * @date 2022/10/14 23:13
 **/
public class Offer26 {
    class Solution {
        public boolean isSubStructure(TreeNode a, TreeNode b) {
            if(a == null || b == null) return false;

            return dfs(a, b) || isSubStructure(a.left, b) || isSubStructure(a.right, b);
        }
        private boolean dfs(TreeNode a, TreeNode b){
            if(b == null) return true;
            if(a == null) return false;
            return a.val == b.val && dfs(a.left, b.left) && dfs(a.right, b.right);
        }
    }
}